package com.qfedu.mesadmin.md.client.controller;

import com.qfedu.mes.common.CommonResult;
import com.qfedu.mes.common.PageParam;
import com.qfedu.mes.common.PageVO;
import com.qfedu.mesadmin.md.client.params.AddClientParam;
import com.qfedu.mesadmin.md.client.params.ClientPageParam;
import com.qfedu.mesadmin.md.client.service.MdClientService;
import com.qfedu.mesadmin.md.client.vo.ClientTypeVO;
import com.qfedu.mesadmin.md.client.vo.MdClientVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/md/client")
public class ClientController {

    @Resource
    private MdClientService mdClientService;

    //所有数据
    @GetMapping("/list")
    public CommonResult selectInfo(PageParam param) {
        PageVO<MdClientVO> mdClientVOS = mdClientService.selectInfo(param);
        return CommonResult.success(mdClientVOS);
    }

    //模糊查询数据
    @GetMapping("/search")
    public CommonResult searchInfo(ClientPageParam param) {
        PageVO<MdClientVO> mdClientVOS = mdClientService.searchInfo(param);
        return CommonResult.success(mdClientVOS);
    }

    //获取类型列表
    @GetMapping("/type")
    public CommonResult searchType() {
        List<ClientTypeVO> clientTypeVOS = mdClientService.selectType();
        return CommonResult.success(clientTypeVOS);
    }

    //添加客户
    @PostMapping("add")
    public CommonResult addInfo(@RequestBody AddClientParam param) {
        mdClientService.insertClient(param);
        return CommonResult.success();
    }

    //根据id删除
    @GetMapping("/delete")
    public CommonResult deleteClient(Long id) {
        mdClientService.deleteById(id);
        return CommonResult.success();
    }

    //更新时展示数据
    @GetMapping("/showInfo")
    public CommonResult showInfo(Long id) {
        AddClientParam addClientParam = mdClientService.selectById(id);
        return CommonResult.success(addClientParam);
    }

    //更新
    @PostMapping("/update")
    public CommonResult updateById(@RequestBody AddClientParam param) {
        mdClientService.updateById(param);
        return CommonResult.success();
    }

    //获取总条数
    @GetMapping("/getTotal")
    public CommonResult getTotal() {
        Integer total = mdClientService.selectTotal();
        return CommonResult.success(total);
    }
}
